<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" import="cn.antia.cep.common.pool.*,java.util.*,cn.antia.cep.common.*,cn.antia.cep.page.*,cn.antia.cep.busi.*"%>
<%@ page import="cn.antia.cwin.Cele" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/FCKeditor.tld" prefix="FCK" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set var="table" value="${param.table}"/>
<c:set var="formSessionName" value="form_${table}"/>
<c:set var="tableSessionName" value="table_${table}"/>
<!--取出FORM对象-->
<c:set var="form" value="${sessionScope[formSessionName]}"/>

<%
String tb = request.getParameter("table");
String tableDefault = PageRule.sessionDefaultName(tb);
String tableTether = PageRule.sessionTetherName(tb);
String defaultV = request.getParameter("default");
String tetherV = request.getParameter("tether");

if(defaultV != null && !defaultV.equals((String)session.getAttribute(tableDefault))){
	session.setAttribute(tableDefault,defaultV);
}
if(tetherV != null && !tetherV.equals((String)session.getAttribute(tableTether))){
	session.setAttribute(tableTether,tetherV);
}

AntiaPoolHelper helper = (AntiaPoolHelper)ContextBean.getBean("antiaPoolHelper");
List comsats = helper.getComsats(tb);
String formRequestnName = PageRule.getSessionName(tb);

//取得默认字段
String dn = PageRule.sessionDefaultName(tb);
String dv = (String)session.getAttribute(dn);
//如果有加入的默认值，则加上
Cele ec;
if(dv != null && dv.trim().length() > 0){
	String[] dvs = dv.split(";");
	String[] temp;
	try{
		for(int i = 0;i<dvs.length;i++){
	temp = dvs[i].split(":");
	for(int j = 0;j<comsats.size();j++){
		ec = (Cele)comsats.get(j);
		if(ec.getField().getFieldName().equals(temp[0])){
			ec.getField().setDefault(temp[1]);
		}
	}
		}
	}catch(Exception e){
		AntiaLog.error("default parameter config error:" + dv);
		out.println("default parameter config error:" + dv);
	}
}
//设置每一个元素的验证字符串
for(int i = 0;i<comsats.size();i++){
	ec = (Cele)comsats.get(i);
	Cele.setValitionString(ec);
}
//取得FORM对象
PageService pageService = (PageService)ContextBean.getBean("pageService");
AntiaForm af = pageService.getAntiaForm(comsats,tb);
//设置
session.setAttribute(formRequestnName,af);

String formaction = request.getParameter("do");
String sessionAction = tb + "_action";
if(formaction == null && session.getAttribute(sessionAction) == null){
	formaction = "dataOperateAction.do";
}else if(session.getAttribute(sessionAction) != null){
	formaction = (String)session.getAttribute(sessionAction);
}
session.setAttribute(sessionAction,formaction);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>主表　${table}　数据录入页面</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="StyleSheet" href="resource/css/default.css" type="text/css"/>
    <link rel="StyleSheet" href="cep/css/cep.css" type="text/css"/>
  </head>

  <script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
  <script type="text/javascript" src="cep/js/validation/validation.js"></script>
  <script type="text/javascript" src="cep/js/validation/form.js"></script>
  <script type="text/javascript" src="cep/js/sort.js"></script>
  <body>
    <b>表&nbsp;${table}&nbsp;维护页 now this page is works OK</b><span style="padding-left:50px;color: #700700" id="easy_mana_err_span">${message }<font color="red"> ${err_msg}</font></span>
    <c:if test = "${form != null}">
    <!-- 显示表属性，并且以表单形式呈现 -->
    <FORM name="${form.formName}" method= "${form.method}" action="<%= formaction%>">
    	<INPUT type="hidden" name="table" value="${table}" /> 
    	<input type="hidden" name="errorMsgSpan" value="easy_mana_err_span">
	    <TABLE width="100%">
	    <c:set var="posi" value="${-1}"></c:set>
    	<c:forEach var="feleO"  items="${form.formList}" varStatus="status">
            <c:set var="fele" value="${feleO.htmlWidget}"></c:set>
            <c:set var="fht" value="${fele.htmlType}"></c:set>
    		<c:set var="fn" value="${feleO.field.fieldName}"></c:set>
    		<c:if test="${fht != 'hidden'}" var = "notHidden" scope="page">
    			<c:set var="posi" value="${posi + 1}"></c:set>
    		</c:if>
    		<c:if test="${notHidden && posi % 2 == 0}">
    		<tr>
    		</c:if>
    		<c:if test="${!notHidden}"><input type = "${fht}" name="${fn}" size="${fele.size}"/></c:if>
    		<c:if test="${notHidden && fht != 'select' && fht != 'textarea' && fht != 'fckeditor'}">
	    		<td>${fele.dispText}</td>
	    		<TD><input type = "${fht}" name="${fn}" value="${fdv}" size="${fele.size}" <c:if test="${fele.readonly}"> readonly="readonly" </c:if> onblur="validElement(this,'${fele.limits}','','')"/></TD>
    		</c:if>
	    		<c:if test = "${fht == 'select'}">
	    			<td>${fele.dispText}</td>
	    			<td>
	    			<SELECT name="${fn}" value="${fdv}" <c:if test="${fele.onchange != null}">onchange = "${fele.onchange}"</c:if> onblur="validElement(this,'${fele.limits}','','')">
	    				<option value="">未选择</option>
	    				<c:forEach var="option" items="${fele.dispList}"><option value="${option.key}">${option.value}</option></c:forEach>
	    			</SELECT>
	    			</td>
	    		</c:if>
	    		<c:if test = "${fht == 'textarea'}">
	    			<td>${fele.dispText}</td>
	    			<td><textarea name="${fn}" rows="${fele.rows}" cols="${fele.cols}" onblur="validElement(this,'${fele.limits}','','')"></textarea></td>
	    		</c:if>
	    		<c:if test = "${fht == 'fckeditor'}">
	    			<c:if test="${posi%2 == 0}">
	    			<td></td></tr><tr>
	    			</c:if>
	    			<c:if test="${posi%2 == 1}"></tr>
		    			<tr>
	    			</c:if>
	    			<td>${fele.dispText}</td>
	    			<td colspan="3">
	    			<textarea id="${fn}" name="${fn}" cols="${fele.cols}" rows="${fele.rows}"></textarea>
						<script type="text/javascript">
						 var oFCKeditor = new FCKeditor('${fn}') ;
						 oFCKeditor.BasePath = 'FCKeditor/';
						 oFCKeditor.ToolbarSet = "Basic" ;
						 oFCKeditor.Height = ${fele.rows};
						 oFCKeditor.Width = ${fele.cols};
						 //oFCKeditor.ToolbarSet = "Gk" ; 
						 oFCKeditor.ReplaceTextarea();
						</script>
	    			</td>
	    			<c:if test="${posi % 2 == 0}">
	    				</tr><tr>
	    			</c:if>
	    		</c:if>
	    	<c:if test="${notHidden && posi % 2 == 1}">
    			</tr>
    		</c:if>
    	</c:forEach>
	<!-- 操作按纽 -->
	<tr>
    <td>
      <input type="button" onclick="addRecord();" value="新  增" id="but_inse"/>
    </td>
    <td colspan="3">
      <input type="button" onclick="operateForm('query');" value="查  询" id="but_quer"/>
      <input type="button" onclick="operateForm('update');" value="保  存" id="but_upda"/>
      <input type="button" onclick="operateForm('delete');" value="删  除" id="but_dele"/>
    </td>
  </tr>
	    </TABLE>
    </FORM>
    </c:if>
    <hr>

    <!-- 显示结果集 -->
    <!--取出Table对象-->
    <c:set var="dtable" value="${requestScope[tableSessionName]}"/>
    <c:set var="noData" value="${empty dtable}"/>
    <c:if test="${!noData}">
    <!-- 显示表头 --><!-- 显示表体 -->
    <div style="width:'3000';height:300;overflow-x:scroll;overflow-y:scroll">
    <TABLE id = "${dtable.tableId}">
    	<tr>
	    	<c:forEach var="valueDisp" items="${dtable.th}">
	    		<td id = "${valueDisp.name}" onclick="sort_this_table()" class="grid_th">${valueDisp.dispText}</td>
	    	</c:forEach>
    	</tr>
    	<c:forEach var="row" items="${dtable.rows}">
    		<tr onclick="copy(this,false)" onmousemove="mOvr(this)" onmouseout="mOut(this)">
    		<c:forEach var="element" items="${row}">
    			<c:set value="${element.name}" var="en1"></c:set>
    			<c:if test="${en1 != null && (en1 == 'hiddendiv' || en1 == 'hidden' || en1 == 'pop')}" var="hid">
    				<c:if test="${en1 == 'hiddendiv'}">
    					<TD><div style="display:none">${element.value}</div></TD>
    				</c:if>
    				<c:if test="${element.name == 'hidden'}">
    					<TD><pre style="display:none">${element.value}</pre></TD>
    				</c:if>
    			</c:if>
    			<c:if test="${!hid}">
    				<TD>${element.value}</TD>
    			</c:if>
    		</c:forEach>
    		</tr>
    	</c:forEach>
    </TABLE>
    </div>
    </c:if>
  </body>
  <script language="javascript">
  //这个方法专为 genus_test 表的操作而写
  function test_type_change(sele){
  	var v = sele.value;
  	if(v != 11){
  		document.f_genus_test.right_answer.disabled = true;
  		document.f_genus_test.right_item.disabled = false;
  	}else if(v == 11){
  		document.f_genus_test.right_answer.disabled = false;
  		document.f_genus_test.right_item.disabled = true;
  	}
  }
  </script>
  <script type="text/javascript" src="cep/js/easymana.js"></script>
  <script type="text/javascript" src="cep/js/easymana_copy_pri.js"></script>
  <script language="javascript">
    setTableId("t_${table}");
	setFormName("${form.formName}");
</script>
</html>
